package com.zjitc.controller;

import com.zjitc.model.*;
import com.zjitc.service.AdminService;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.omg.CORBA.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceView;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/19 15:46
 * @description:
 */


public class AdminProduct {
  @Autowired
  AdminService adminService;
  private ModelAndView mv =new ModelAndView();
  @RequestMapping("/finduserList")
  public ModelAndView userList(){
    List<User> userList = adminService.finduserList();
    mv.addObject("userList",userList);
    mv.setView(new InternalResourceView("/admin/user/list.jsp"));
    return mv;
  }
  @RequestMapping("/quit")
  public String quit(){
    return "/admin/login.jsp";
  }
  @RequestMapping("/category")
  public ModelAndView category(){
    List<Category> categoryList=adminService.findCatefory();
    mv.addObject("categoryList",categoryList);
    mv.setView(new InternalResourceView("/admin/catefory/list.jsp"));
    return mv;
  }
  @RequestMapping("/categorySecond")
  public ModelAndView categorySecond(){
    List<CategorySecond> categorySecondList=adminService.findCateforySecond();
    mv.addObject("categorySecondList",categorySecondList);
    mv.setView(new InternalResourceView("/admin/cateforysecond/list.jsp"));
    return mv;
  }
  @RequestMapping("/addcategory")
  public ModelAndView addcategory(@RequestParam("cid") Integer cid,
                                  @RequestParam("cname") String cname){
     adminService.addcategory(cid,cname);
     mv.setView(new InternalResourceView("category.do"));
     return mv;
  }
  @RequestMapping("/addcategorySecond")
  public ModelAndView addcategorySecond(@RequestParam("csid")   Integer csid,
                                        @RequestParam("csname") String csname,
                                        @RequestParam("cid")    Integer cid){
    adminService.addcategorySecond(csid,csname,cid);
    mv.setView(new InternalResourceView("categorySecond.do"));
    return mv;
  }
  @RequestMapping("/deleteCategory")
  public ModelAndView deleteCategory(@RequestParam("pid") Integer pid){
    adminService.deleteCategory();
    mv.setView(new InternalResourceView("category.do"));
    return mv;
  }
  @RequestMapping("/deletecategorySecond")
  public ModelAndView deletecategorySecond(@RequestParam("csid") Integer csid ){
    adminService.deletecategorySecond();
    mv.setView(new InternalResourceView("categorySecond.do"));
    return mv;
  }
  @RequestMapping("/adminFindProductByPid")
  public ModelAndView findProducts(){
    List<Product> pid=adminService.findPid();
    mv.addObject("pid",pid);
    mv.setView(new InternalResourceView("/admin/product/list.jsp"));
    return mv;
  }
  @RequestMapping("/adminDeleteByPid")
  public ModelAndView adminDeleteByPid(@RequestParam("pid")Integer pid){
    adminService.adminDeleteByPid(pid);
    mv.setView(new InternalResourceView("/admin/product/list.jsp"));
    return mv;
  }







}
